﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MINERP.DAL;
using MINERP.COM;

namespace MINERP.BLL.Common
{
    /// <summary>
    /// 主要用于监控各种状态的大板\产品的数量
    /// </summary>
    public class BoardStatsMonitorBLL
    {
        public static List<string> GetAllBoardStausAndQutiy()
        {
            List<string> resultList = new List<string>();

            using (newSampleYPDBEntities db = new newSampleYPDBEntities())
            {
                int boardCompletedStatus = (int)EnumBoardStatus.Printed;
                int boardProductingStatus = (int)EnumBoardStatus.ProductIng;
                int BoardPrintingStatus = (int)EnumBoardStatus.Printing;

                List<Board> allBoard = db.Board.Where(b => b.status != boardCompletedStatus && b.status != boardProductingStatus && b.status != BoardPrintingStatus).ToList();

                foreach (var statsBoards in allBoard.GroupBy(b => b.status))
                {
                    string statsuName = GetBoardStatusNameFromKey(statsBoards.Key);

                    foreach (var boardSize in statsBoards.GroupBy(b => b.width))
                    {
                        int dpi = boardSize.FirstOrDefault().DPI;

                        resultList.Add(Convert.ToInt32(boardSize.Key / dpi) + "寸" + statsuName + ":" + boardSize.Count());
                    }
                }
            }

            return resultList;
        }

        /// <summary>
        /// 得到等待移动图片、暂停、余额不足的产品的数量
        /// </summary>
        /// <returns></returns>
        public static List<string> GetALLOrderInfoStatusQutiy()
        {
            List<string> resultList = new List<string>();

            int orderInfoStopStatus = (int)OrderInfoStatus.Stop;//客服暂停

            int orderInfoWaitPayStatus1 = (int)OrderInfoStatus.WaitPay;//余额不足
            int orderInfoWaitPayStatus2 = (int)OrderInfoStatus.NoCheckCount;

            int orderInfoWatiMovePhotoStatus1 = (int)OrderInfoStatus.WaitPhotoMove;//移动图片
            int orderInfoWatiMovePhotoStatus2 = (int)OrderInfoStatus.WaitPayAndWaitMovePhoto;


            using (newSampleYPDBEntities db = new newSampleYPDBEntities())
            {
                var count = db.orderInfo.Count(o => o.status == orderInfoStopStatus);
                if (count != 0)
                {
                    resultList.Add("暂停：" + count);
                }
                else
                {
                    resultList.Add("无暂停");
                }
                count = db.orderInfo.Count(o => o.status == orderInfoWaitPayStatus1 && o.status == orderInfoWaitPayStatus2);
                if (count != 0)
                {
                    resultList.Add("欠款：" + count);
                }
                else
                {
                    resultList.Add("无欠款");
                }
                count = db.orderInfo.Count(o => o.status == orderInfoWatiMovePhotoStatus1 && o.status == orderInfoWatiMovePhotoStatus2);
                if (count != 0)
                {
                    resultList.Add("移动图片：" + count);
                }
                else
                {
                    resultList.Add("无移动图片");
                }
            }

            return resultList;
        }

        private static string GetBoardStatusNameFromKey(int intBoardStatus)
        {
            EnumBoardStatus bs = (EnumBoardStatus)intBoardStatus;
            switch (bs)
            {
                case EnumBoardStatus.WaitingPrint: return "等待打印";
                    break;
                case EnumBoardStatus.Printing: return "正在打印";
                    break;
                case EnumBoardStatus.Printed: return "打印完成";
                    break;
                case EnumBoardStatus.waitProduct: return "等待生成大图";
                    break;
                case EnumBoardStatus.ProductIng: return "正在生成大图";
                    break;
                case EnumBoardStatus.Error: return "错误";
                    break;
                case EnumBoardStatus.Pause: return "暂停";
                    break;
                case EnumBoardStatus.NotFindBigPic: return "没有找到大图";
                    break;
                case EnumBoardStatus.WaitEncrypt: return "系统状态";
                    break;
                default: return "空NULL";
                    break;
            }
        }
    }
}
